<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>视频详情</title>
    <link rel="stylesheet" href="../css/videoDetail.css">
</head>
<body>
    <p class="title"></p>
    <p class="time"></p>
    <p class="source"></p>

    <img class="leftImg" src="../images/imgDetail/img.png" alt="">

    <p class="contentTitle">内容简介</p>
    <div class="content"><div id="content"></div></div>

    <div id="play"><p>播放</p></div>
    <p class="changePage">
        <img src="../images/imgDetail/last.png" alt="">
        <img src="../images/imgDetail/next.png" alt="">
        <span>翻页</span>
    </p>
    <p class="page">1/3</p>

    <script src="../js/yajax.js"></script>
    <script src="../js/use.js"></script>
    <script src="../js/S.js"></script>
    <script src="../js/common.js"></script>
    <script type="text/javascript">
        var clickFunction = function(keyEvent){
            keyEvent = keyEvent ? keyEvent : window.event;
            keyEvent.which = keyEvent.which ? keyEvent.which : keyEvent.keyCode;
            keycontrol(keyEvent);
        };
        //window.document.onkeypress = clickFunction;
        window.document.onkeydown = clickFunction;
        //按键操作
        function keycontrol(obj) {
            if (obj.which == 0x0026) {
                /* 上 */
                keyopt.moveBtn("go_top");
            } else if (obj.which == 0x0028) {
                /* 下 */
                keyopt.moveBtn("go_bottom");
            } else if (obj.which == 0x0025) {
                /* 左 */
                keyopt.moveBtn("go_left");
            } else if (obj.which == 0x0027) {
                /* 右 */
                keyopt.moveBtn("go_right");
            } else if (obj.which == 0x000D) {
                /* 确定 */
                keyopt.marksure();
            } else if ((obj.which <= 0x0039 && obj.which >= 0x0030) || obj.which == 0x118 || obj.which == 280) {//数字键输入
                keyopt.input(obj.which);
            } else if (obj.which == 113 || obj.which == 0x0008) {// 返回
                obj.stopPropagation();
                obj.preventDefault();
                history.go(-1);
            }
        }

        //操作类型
        var keyopt = {
            options : {
                focusElm : "play"
            },
            moveBtn : function(toDirection) {
                // 移动之前的id
                var oldBtnId = this.options.focusElm;
                // 将移动之前的元素json信息解析成json对象
                var old_obj_json = eval(oldBtnId + "_json");
                // 获取移动目的地的id信息
                var goElm = old_obj_json[toDirection];
                if (goElm == "") {
                    goElm = oldBtnId;
                }
                var new_btn = document.getElementById(goElm);
                if (new_btn) {
                    var onfocusFuc = eval(goElm + "_onfocus");  //之后ID的blur方法
                    var onblurFuc = eval(oldBtnId + "_onblur");  //之前ID的focus方法
                    onblurFuc(toDirection, oldBtnId);//go_buttom,top1
                    this.options.focusElm = goElm;
                    onfocusFuc(toDirection, goElm);//go_buttom,top2
                }
            },
            marksure : function() {
                if(document.getElementById(this.options.focusElm)){
                    var onsubmitFuc = eval(this.options.focusElm + "_onsubmit");
                    onsubmitFuc('',this.options.focusElm);
                }
            },
            input : function(code) {
                var onkeypressFuc = eval(this.options.focusElm + "_onkeypress");
                onkeypressFuc(code);
            },
            moveToElm : function(id) {
                var to_elm = document.getElementById(id);
                if (to_elm) {
                    var onfocusFuc = eval(id + "_onfocus");
                    var onblurFuc = eval(this.options.focusElm + "_onblur");
                    onfocusFuc();
                    this.options.focusElm = id;
                    onblurFuc();
                }
            },
            addClass : function(id, className) {
                document.getElementById(id).className += " " + className;
            },
            removeClass : function(id, className) {//top1,,,top
                document.getElementById(id).className = document.getElementById(id).className      //class="1"
                        .replace(className, '');
            },
            replaceClass : function(id, searchClass, replaceClass) {
                var className = document.getElementById(id).className;
                document.getElementById(id).className = className.replace(searchClass,
                        replaceClass)
            }
        };


        var str;
        var page=0;//当前页数
        var pageH=300;//每页高度，与文字显示高度相同
        var pageMax=1;//最大页数

        function setPage(num){//翻页，num为0表示上一页，num为1表示是下一页
            if(num==0&&page!=0){
                page--;
                document.getElementById('content').style.top=-page*pageH+'px';
                document.getElementsByClassName("page")[0].innerHTML=(page+1)+'/'+pageMax;
            }else if(num==1&&page<pageMax-1){
                page++;
                document.getElementById('content').style.top=-page*pageH+'px';
                document.getElementsByClassName("page")[0].innerHTML=(page+1)+'/'+pageMax;
            }
        }

        //截取传值参数
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
            var r = window.location.search.substr(1).match(reg);
            if (r!=null) return (r[2]); return null;
        }

        var id=GetQueryString('id');

        var videoName;
        //获取详情页
        function getDetail(){
            new YAjax().request({
                url: CONFIG.HTTP + CONFIG.VILLAGE_URLS[0].getgetWanYuanContentCulars + '&objId='+id+'&pageIndex=0&pageSize=1&loginToken=' + LOGIN_TOKEN,
                method: "GET",
                success: function (data) {
                    var obj = JSON.parse(data);
                    console.log(obj);
                    var str=obj.datas[0].content;
                    document.getElementById('content').innerHTML='<p>'+str.replace(/&lt;br\/&gt;/g,'</p><p>')+'</p>';
                    pageMax=Math.ceil(document.getElementById('content').offsetHeight/pageH);
                    document.getElementsByClassName("page")[0].innerHTML=(page+1)+'/'+pageMax;
                    use.setSlide('slide',obj.datas[0].titleName,35,"title",0);  // 设置标题。滑动或者静止显示
                    videoName=obj.datas[0].tvFilePath;
                    if(obj.datas[0].postTime==""){
                        document.getElementsByClassName("time")[0].innerHTML=obj.datas[0].createTime.substring(0,10);
                    }else{
                        document.getElementsByClassName("time")[0].innerHTML=obj.datas[0].postTime;
                    }

                    document.getElementsByClassName("source")[0].innerHTML=obj.datas[0].source;
                    if(obj.datas[0].pictures==""){
                        document.getElementsByClassName("leftImg")[0].src='../images/imgDetail/img.png';
                    }else{
                        document.getElementsByClassName("leftImg")[0].src=CONFIG.IMAGE_RESOURCES_ADDRESS+obj.datas[0].pictures;
                    }
                }
            })
        }
        getDetail();

        var play_json={
            "go_left":"play",
            "go_top": "play",
            "go_right": "play",
            "go_bottom": "play"
        };
        var play_onfocus = function (code,id){

        };
        var play_onblur = function (code,id) {
            if(code=="go_left"){
                setPage(0);
            }
            else if(code=="go_right"){
                setPage(1);
            }

        };
        var play_onsubmit = function (code,id) {
            location.href="player.html?video_url="+CONFIG.VIDEO_RESOURCES_ADDRESS+encodeURI(videoName);
        };

        //base64编码解码
        function Base64() {
            // public method for encoding
            // private property
            _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
            this.encode = function (input) {
                var output = "";
                var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
                var i = 0;
                input = _utf8_encode(input);
                while (i < input.length) {
                    chr1 = input.charCodeAt(i++);
                    chr2 = input.charCodeAt(i++);
                    chr3 = input.charCodeAt(i++);
                    enc1 = chr1 >> 2;
                    enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
                    enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
                    enc4 = chr3 & 63;
                    if (isNaN(chr2)) {
                        enc3 = enc4 = 64;
                    } else if (isNaN(chr3)) {
                        enc4 = 64;
                    }
                    output = output +
                            _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
                            _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
                }
                return output;
            };

            // public method for decoding
            this.decode = function (input) {
                var output = "";
                var chr1, chr2, chr3;
                var enc1, enc2, enc3, enc4;
                var i = 0;
                input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
                while (i < input.length) {
                    enc1 = _keyStr.indexOf(input.charAt(i++));
                    enc2 = _keyStr.indexOf(input.charAt(i++));
                    enc3 = _keyStr.indexOf(input.charAt(i++));
                    enc4 = _keyStr.indexOf(input.charAt(i++));
                    chr1 = (enc1 << 2) | (enc2 >> 4);
                    chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
                    chr3 = ((enc3 & 3) << 6) | enc4;
                    output = output + String.fromCharCode(chr1);
                    if (enc3 != 64) {
                        output = output + String.fromCharCode(chr2);
                    }
                    if (enc4 != 64) {
                        output = output + String.fromCharCode(chr3);
                    }
                }
                output = _utf8_decode(output);
                return output;
            };

            // private method for UTF-8 encoding
            _utf8_encode = function (string) {
                string = string.replace(/\r\n/g,"\n");
                var utftext = "";
                for (var n = 0; n < string.length; n++) {
                    var c = string.charCodeAt(n);
                    if (c < 128) {
                        utftext += String.fromCharCode(c);
                    } else if((c > 127) && (c < 2048)) {
                        utftext += String.fromCharCode((c >> 6) | 192);
                        utftext += String.fromCharCode((c & 63) | 128);
                    } else {
                        utftext += String.fromCharCode((c >> 12) | 224);
                        utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                        utftext += String.fromCharCode((c & 63) | 128);
                    }

                }
                return utftext;
            };

            // private method for UTF-8 decoding
            _utf8_decode = function (utftext) {
                var string = "";
                var i = 0;
                var c = c1 = c2 = 0;
                while ( i < utftext.length ) {
                    c = utftext.charCodeAt(i);
                    if (c < 128) {
                        string += String.fromCharCode(c);
                        i++;
                    } else if((c > 191) && (c < 224)) {
                        c2 = utftext.charCodeAt(i+1);
                        string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                        i += 2;
                    } else {
                        c2 = utftext.charCodeAt(i+1);
                        c3 = utftext.charCodeAt(i+2);
                        string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                        i += 3;
                    }
                }
                return string;
            }
        }
    </script>
</body>
</html>